<?php

namespace qore_base\base;

/**
 * @author Samuel Nogueira <samuel.nogueira.dev@gmail.com>
 */
abstract class Controller extends Component {
	
	/**
	 * Returns an array with all available actions for this controller
	 * @return string[]
	 */
	public function getAvailableActions() {
		// we are using a Closure so the scope is the outside of this object,
		// therefore, the returned methods will be public
		$className = get_class($this);
		$getPublicMethods = function() use ($className) {
			return get_class_methods($className);
		};
		
		$actions = array();
		foreach ($getPublicMethods() as $method) {
			if (preg_match('/^action(?<actionName>.*)/i', $method, $matches)) {
				$actions[] = strtolower($matches['actionName']);
			}
		}
		return $actions;
	}
	
}